$(function(){
	$('#keywordList').hide();
	
	$('#searchOne').click(function(){
		if(!$('#keywordList').is(':hidden')){
			return;
		}
		
		$('#keywordList').show();
		
		requestData('json/searchOne.json', function(data, textStatus, jqXHR){
			if(data && data.code == 0){
				$('#keyListTemplate').tmpl(data.data).appendTo('#keywordList');
			}else{
				
			}
		});
		
		//接口
		//requestTopicWordtoWord(32);
	});
	
});

function hmProxy(url, data, callback){
	var prefix = localStorage.localIP;
	//if(!url.startsWith('/')){
	//	prefix += '/';
	//}
	$.ajax({
		type: 'post',
		url: prefix + url + '.json?message=' + JSON.stringify(data),
		dataType: 'json',
		success: callback
	});
};

function requestTopicWordtoWord(id){
	var json = {
			"id": id
		};
	
	hmProxy('topic/topicWordtoWord', json, function(data, textStatus, jqXHR){
		data = eval("("+data+")");
		if(data && data.ret == 0){
			var list = data.data;
			if(list && list.length > 0){
				var keywordHtml = "";
				list.forEach(function(obj){
					keywordHtml += "<li id='hotKeyHint'><a href='#' style='color:#568bce;'>"+obj.topicword+"</a></li>";
					var words = obj.words;
					if(words && words.length > 0){
						words.forEach(function(word){
							keywordHtml += "<li><a href='searchResult.html?key="+encodeURI(encodeURI(word.word))+"'>"+word.word+"</a></li>";
						});
					}
				});
				
				$("#keywordList").html(keywordHtml);
			}
		}
	});
};